﻿using Sunny.UI;
using System.Net.Sockets;
using System.Net;
using System.Configuration;
using System.Threading;
using System;
using System.Windows.Forms;

namespace FZRD
{
    public partial class Page3 : UIPage
    {
        //监听线程
        //[DisallowNull]
        public static Thread receiveThread3;
        //应变传感器1应变光栅初始波长
        private static double S1A1 = 1552.638;
        //应变传感器1温度光栅初始波长
        private static double S1A2 = 1534.793;
        //应变传感器2应变光栅初始波长
        private static double S2A1 = 1558.238;
        //应变传感器2温度光栅初始波长
        private static double S2A2 = 1554.753;
        //应变传感器1应变光栅系数
        private static double S1K1 = 0.00177;
        //应变传感器1温度光栅系数
        private static double S1K2 = 0.0105;
        //应变传感器1应变光栅温度系数
        private static double S1K3 = 0.0287;
        //应变传感器2应变光栅系数
        private static double S2K1 = 0.00185;
        //应变传感器2温度光栅系数
        private static double S2K2 = 0.01025;
        //应变传感器2应变光栅温度系数
        private static double S2K3 = 0.0298;
        //应变传感器弹性模量(T1)
        private static double EM1 = 0.068348;
        //应变传感器弹性模量(T2)
        private static double EM2 = 2444.0651;
        //应变传感器初始轴力(F1)
        private static double AF1 = 8665.69;
        //应变传感器初始轴力(F2)
        private static double AF2 = 1698.665046;
        //π(PI)
        private static double PI = 3.1415926;
        //项目方提供
        private static double PE = 322568.55;

        private static bool isAlarmNotify = true;
        private static double axialForceExceeds = 10000.0;
        private static int repeatTimes = 100;

        private static bool isAlarmEmail = true;
        private static string alarmEmail = "";

        private static bool isAlarmPhone = true;
        private static string alarmPhone = "";

        //温度传感器初始光栅波长
        private static double tempStartWave = 1550.110;
        //温度传感器初始温度
        private static double tempStartValue = 25;

        //位移传感器初始光栅波长1
        private static double moveStartWave10 = 1546.810;
        //位移传感器初始光栅波长2
        private static double moveStartWave20 = 1544.867;
        //位移传感器 A,B,C 为多项式系数
        private static double A = 3.936;
        private static double B = 32.61209283;
        private static double C = 0.043463267;

        public Page3()
        {
            InitializeComponent();


            this.tbScanFrequency.Text = ConfigurationManager.AppSettings["tbScanFrequency"];
            this.tbWaveOffset.Text = ConfigurationManager.AppSettings["tbWaveOffset"];

            this.tbPeakSeekParam1.Text = ConfigurationManager.AppSettings["tbPeakSeekParam1"];
            this.tbPeakSeekParam2.Text = ConfigurationManager.AppSettings["tbPeakSeekParam2"];
            this.tbPeakSeekParam3.Text = ConfigurationManager.AppSettings["tbPeakSeekParam3"];
            this.tbPeakSeekParam4.Text = ConfigurationManager.AppSettings["tbPeakSeekParam4"];
            this.tbPeakSeekParam5.Text = ConfigurationManager.AppSettings["tbPeakSeekParam5"];
            this.tbPeakSeekParam6.Text = ConfigurationManager.AppSettings["tbPeakSeekParam6"];
            this.tbPeakSeekParam7.Text = ConfigurationManager.AppSettings["tbPeakSeekParam7"];
            this.tbPeakSeekParam8.Text = ConfigurationManager.AppSettings["tbPeakSeekParam8"];
            this.tbPeakSeekParam9.Text = ConfigurationManager.AppSettings["tbPeakSeekParam9"];
            this.tbPeakSeekParam10.Text = ConfigurationManager.AppSettings["tbPeakSeekParam10"];
            this.tbPeakSeekParam11.Text = ConfigurationManager.AppSettings["tbPeakSeekParam11"];
            this.tbPeakSeekParam12.Text = ConfigurationManager.AppSettings["tbPeakSeekParam12"];
            this.tbPeakSeekParam13.Text = ConfigurationManager.AppSettings["tbPeakSeekParam13"];
            this.tbPeakSeekParam14.Text = ConfigurationManager.AppSettings["tbPeakSeekParam14"];
            this.tbPeakSeekParam15.Text = ConfigurationManager.AppSettings["tbPeakSeekParam15"];
            this.tbPeakSeekParam16.Text = ConfigurationManager.AppSettings["tbPeakSeekParam16"];

            this.tbFlexWave1.Text = ConfigurationManager.AppSettings["tbFlexWave1"];
            this.tbFlexWave2.Text = ConfigurationManager.AppSettings["tbFlexWave2"];
            this.tbTempWave1.Text = ConfigurationManager.AppSettings["tbTempWave1"];
            this.tbTempWave2.Text = ConfigurationManager.AppSettings["tbTempWave2"];

            this.tbStrainCoefficient1.Text = ConfigurationManager.AppSettings["tbStrainCoefficient1"];
            this.tbStrainCoefficient2.Text = ConfigurationManager.AppSettings["tbStrainCoefficient2"];

            this.tbTempCoefficient1.Text = ConfigurationManager.AppSettings["tbTempCoefficient1"];
            this.tbTempCoefficient2.Text = ConfigurationManager.AppSettings["tbTempCoefficient2"];

            this.tbStrainTempCoefficient1.Text = ConfigurationManager.AppSettings["tbStrainTempCoefficient1"];
            this.tbStrainTempCoefficient2.Text = ConfigurationManager.AppSettings["tbStrainTempCoefficient2"];

            this.tbElasticModulus1.Text = ConfigurationManager.AppSettings["tbElasticModulus1"];
            this.tbElasticModulus2.Text = ConfigurationManager.AppSettings["tbElasticModulus2"];

            this.tbAxialForce1.Text = ConfigurationManager.AppSettings["tbAxialForce1"];
            this.tbAxialForce2.Text = ConfigurationManager.AppSettings["tbAxialForce2"];
            this.tbAxialForce3.Text = ConfigurationManager.AppSettings["tbAxialForce3"];

            isAlarmNotify = Convert.ToBoolean(ConfigurationManager.AppSettings["cbAlarmNotify"]);
            this.cbAlarmNotify.Checked = isAlarmNotify;

            axialForceExceeds = Convert.ToDouble(ConfigurationManager.AppSettings["tbAxialForceExceeds"]);
            this.tbAxialForceExceeds.Text = axialForceExceeds.ToString();

            repeatTimes = Convert.ToInt16(ConfigurationManager.AppSettings["tbRepeatTimes"]);
            this.tbRepeatTimes.Text = repeatTimes.ToString();

            isAlarmPhone = Convert.ToBoolean(ConfigurationManager.AppSettings["cbAlarmPhone"]);
            this.cbAlarmPhone.Checked = isAlarmPhone;

            this.tbAlarmPhone.Text = ConfigurationManager.AppSettings["tbAlarmPhone"];
            alarmPhone = this.tbAlarmPhone.Text;

            isAlarmEmail = Convert.ToBoolean(ConfigurationManager.AppSettings["cbAlarmEmail"]);
            this.cbAlarmEmail.Checked = isAlarmEmail;

            this.tbAlarmEmail.Text = ConfigurationManager.AppSettings["tbAlarmEmail"];
            alarmEmail = this.tbAlarmEmail.Text;

            tempStartWave = Convert.ToDouble(ConfigurationManager.AppSettings["tempStartWave"]);
            this.tbTempStartWave.Text = tempStartWave.ToString();

            tempStartValue = Convert.ToDouble(ConfigurationManager.AppSettings["tempStartValue"]);
            this.tbTempStartValue.Text = tempStartValue.ToString();

            moveStartWave10 = Convert.ToDouble(ConfigurationManager.AppSettings["moveStartWave10"]);
            this.tbStartWave10.Text = moveStartWave10.ToString();

            moveStartWave20 = Convert.ToDouble(ConfigurationManager.AppSettings["moveStartWave20"]);
            this.tbStartWave20.Text = moveStartWave20.ToString();

            A = Convert.ToDouble(ConfigurationManager.AppSettings["A"]);
            this.tbA.Text = A.ToString();

            B = Convert.ToDouble(ConfigurationManager.AppSettings["B"]);
            this.tbB.Text = B.ToString();

            C = Convert.ToDouble(ConfigurationManager.AppSettings["C"]);
            this.tbC.Text = C.ToString();


            //开启接收消息线程
            //receiveThread3 = new Thread(ReciveMessage);
            //receiveThread3.Start();
        }

        //窗口关闭事件委托，在窗口关闭事件前处理
        private void Page3_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (receiveThread3 != null)
            {
                receiveThread3.Interrupt();
            }
        }

        public static double getS1A1()
        {
            return S1A1;
        }

        public static double getS1A2()
        {
            return S1A2;
        }

        public static double getS2A1()
        {
            return S2A1;
        }

        public static double getS2A2()
        {
            return S2A2;
        }

        public static double getS1K1()
        {
            return S1K1;
        }

        public static double getS1K2()
        {
            return S1K2;
        }

        public static double getS1K3()
        {
            return S1K3;
        }
        public static double getS2K1()
        {
            return S2K1;
        }
        public static double getS2K2()
        {
            return S2K2;
        }
        public static double getS2K3()
        {
            return S2K3;
        }
        public static double getEM1()
        {
            return EM1;
        }
        public static double getEM2()
        {
            return EM2;
        }
        public static double getAF1()
        {
            return AF1;
        }
        public static double getAF2()
        {
            return AF2;
        }
        public static double getPE()
        {
            return PE;
        }
        public static double getPI()
        {
            return PI;
        }
        public static bool getIsAlarmNotify()
        {
            return isAlarmNotify;
        }
        public static double getAxialForceExceeds()
        {
            return axialForceExceeds;
        }
        public static int getRepeatTimes()
        {
            return repeatTimes;
        }
        public static bool getIsAlarmPhone()
        {
            return isAlarmPhone;
        }
        public static string getAlarmPhone()
        {
            return alarmPhone;
        }
        public static bool getIsAlarmEmail()
        {
            return isAlarmEmail;
        }
        public static string getAlarmEmail()
        {
            return alarmEmail;
        }

        public static double getTempStartWave()
        {
            return tempStartWave;
        }
        public static double getTempStartValue()
        {
            return tempStartValue;
        }
        public static double getMoveStartWave10()
        {
            return moveStartWave10;
        }
        public static double getMoveStartWave20()
        {
            return moveStartWave20;
        }
        public static double getA()
        {
            return A;
        }
        public static double getB()
        {
            return B;
        }
        public static double getC()
        {
            return C;
        }

        private void ReciveData(byte[] revData)
        {
            byte head = revData[0];
            byte cmd = revData[1];

            if (cmd == 0x02)
            {

            }
            else if (cmd == 0x04)
            {

            }
            else if (cmd == 0x06)
            {

            }
            else if (cmd == 0x07)
            {

            }
            else if (cmd == 0x08)
            {

            }
            else if (cmd == 0x0A)
            {

            }
            else if (cmd == 0x0C)
            {

            }
            else if (cmd == 0x14)
            {

            }
            else if (cmd == 0x16)
            {

            }
            else if (cmd == 0x17)
            {

            }
            else if (cmd == 0x24)
            {

            }
            else if (cmd == 0x26)
            {
                byte valueL = revData[2];
                byte valueH = revData[3];
                this.tbWaveOffset.Text = Convert.ToInt32(valueL + valueH * 256) + "";
                //if (receiveThread3 != null){
                //    receiveThread3.Interrupt();
                //}
            }
            else if (cmd == 0x2E)
            {

            }
            else if (cmd == 0x30)
            {
                byte valueL = revData[2];
                byte valueH = revData[3];
                this.tbScanFrequency.Text = Convert.ToInt32(valueL + valueH * 256) + "";
                //if (receiveThread3 != null){
                //    receiveThread3.Interrupt();
                //}
            }
            else if (cmd == 0x32)
            {

            }
            else if (cmd == 0x34)
            {
                byte valueL1 = revData[2];
                byte valueH1 = revData[3];
                this.tbPeakSeekParam1.Text = Convert.ToInt32(valueL1 + valueH1 * 256) + "";
                byte valueL2 = revData[4];
                byte valueH2 = revData[5];
                this.tbPeakSeekParam2.Text = Convert.ToInt32(valueL2 + valueH2 * 256) + "";
                byte valueL3 = revData[6];
                byte valueH3 = revData[7];
                this.tbPeakSeekParam3.Text = Convert.ToInt32(valueL3 + valueH3 * 256) + "";
                byte valueL4 = revData[8];
                byte valueH4 = revData[9];
                this.tbPeakSeekParam4.Text = Convert.ToInt32(valueL4 + valueH4 * 256) + "";
                byte valueL5 = revData[10];
                byte valueH5 = revData[11];
                this.tbPeakSeekParam5.Text = Convert.ToInt32(valueL5 + valueH5 * 256) + "";
                byte valueL6 = revData[12];
                byte valueH6 = revData[13];
                this.tbPeakSeekParam6.Text = Convert.ToInt32(valueL6 + valueH6 * 256) + "";
                byte valueL7 = revData[14];
                byte valueH7 = revData[15];
                this.tbPeakSeekParam7.Text = Convert.ToInt32(valueL7 + valueH7 * 256) + "";
                byte valueL8 = revData[16];
                byte valueH8 = revData[17];
                this.tbPeakSeekParam8.Text = Convert.ToInt32(valueL8 + valueH8 * 256) + "";
                byte valueL9 = revData[18];
                byte valueH9 = revData[19];
                this.tbPeakSeekParam9.Text = Convert.ToInt32(valueL9 + valueH9 * 256) + "";
                byte valueL10 = revData[20];
                byte valueH10 = revData[21];
                this.tbPeakSeekParam10.Text = Convert.ToInt32(valueL10 + valueH10 * 256) + "";
                byte valueL11 = revData[22];
                byte valueH11 = revData[23];
                this.tbPeakSeekParam11.Text = Convert.ToInt32(valueL11 + valueH11 * 256) + "";
                byte valueL12 = revData[24];
                byte valueH12 = revData[25];
                this.tbPeakSeekParam12.Text = Convert.ToInt32(valueL12 + valueH12 * 256) + "";
                byte valueL13 = revData[26];
                byte valueH13 = revData[27];
                this.tbPeakSeekParam13.Text = Convert.ToInt32(valueL13 + valueH13 * 256) + "";
                byte valueL14 = revData[28];
                byte valueH14 = revData[29];
                this.tbPeakSeekParam14.Text = Convert.ToInt32(valueL14 + valueH14 * 256) + "";
                byte valueL15 = revData[30];
                byte valueH15 = revData[31];
                this.tbPeakSeekParam15.Text = Convert.ToInt32(valueL15 + valueH15 * 256) + "";
                byte valueL16 = revData[32];
                byte valueH16 = revData[33];
                this.tbPeakSeekParam16.Text = Convert.ToInt32(valueL16 + valueH16 * 256) + "";
                //if (receiveThread3 != null){
                //    receiveThread3.Interrupt();
                //}
            }
            else
            {

            }
        }
        // 接收发送给本机IP对应端口号的数据报
        private void ReciveMessage()
        {
            Socket serverSocket = MainForm.getServerSocket();
            if (serverSocket == null){
                return;
            }
            try
            {
                while (MainForm.getOpenServerPort())
                {
                    //用来保存发送方的IP和端口号
                    EndPoint point = new IPEndPoint(IPAddress.Any, 0);
                    //消息缓存区申请
                    byte[] buffer = new byte[1024];
                    //接收数据报
                    int length = serverSocket.ReceiveFrom(buffer, ref point);
                    byte[] revBuf = new byte[length];
                    Buffer.BlockCopy(buffer, 0, revBuf, 0, length);
                    //显示在视图里
                    this.ReciveData(revBuf);
                }
            }
            catch (SocketException e)
            {
                //MessageBox.Show("接收发送给本机IP对应端口号的数据报错！" + e.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                //if (serverSocket != null){
                //    if (serverSocket.Connected)
                //    {
                //        serverSocket.Disconnect(false);
                //    }
                //    serverSocket.Close();
                //    serverSocket.Dispose();
                //}
            }
        }
        private void btnReadWaveOffset_Click(object sender, EventArgs e)
        {
            bool isOpenServerPort = MainForm.getOpenServerPort();
            if (!isOpenServerPort)
            {
                MessageBox.Show("请先打开服务端口！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Socket serverSocket = MainForm.getServerSocket();
            if (serverSocket == null){
                return;
            }
            EndPoint endPoint = MainForm.getEndPoint();
            //停用按钮，防止多次点击
            this.tbWaveOffset.Enabled = false;
            this.btnReadWaveOffset.Enabled = false;
            try
            {
                //如果不为空
                byte[] bmsg = { 0x01, 0x26 };
                if (bmsg != null)
                {
                    //UI显示
                    this.tbWaveOffset.Enabled = true;
                    this.btnReadWaveOffset.Enabled = true;

                    //发送数据包
                    serverSocket.SendTo(bmsg, endPoint);
                }
                else
                {
                    MessageBox.Show("发送数据格式错误：" + bmsg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (SocketException es)
            {
                MessageBox.Show("发送数据报时出现异常：" + es.ErrorCode + "！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.tbWaveOffset.Enabled = true;
            this.btnReadWaveOffset.Enabled = true;

        }

        private void btnResetWaveOffset_Click(object sender, EventArgs e)
        {
            bool isOpenServerPort = MainForm.getOpenServerPort();
            if (!isOpenServerPort)
            {
                MessageBox.Show("请先打开服务端口！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Socket serverSocket = MainForm.getServerSocket();
            if (serverSocket == null){
                return;
            }
            EndPoint endPoint = MainForm.getEndPoint();
            //停用按钮，防止多次点击
            this.tbWaveOffset.Enabled = false;
            this.btnResetWaveOffset.Enabled = false;
            try
            {
                short offset = Convert.ToInt16(this.tbWaveOffset.Text);
                byte data = Convert.ToByte(offset);
                //如果不为空
                byte[] bmsg = { 0x01, 0x24, data };
                if (bmsg != null)
                {
                    //UI显示
                    this.tbWaveOffset.Enabled = true;
                    this.btnResetWaveOffset.Enabled = true;

                    //发送数据包
                    serverSocket.SendTo(bmsg, endPoint);
                }
                else
                {
                    MessageBox.Show("发送数据格式错误：" + bmsg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (SocketException es)
            {
                MessageBox.Show("发送数据报时出现异常：" + es.ErrorCode + "！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.tbWaveOffset.Enabled = true;
            this.btnResetWaveOffset.Enabled = true;
        }

        private void btnReadFrequency_Click(object sender, EventArgs e)
        {
            bool isOpenServerPort = MainForm.getOpenServerPort();
            if (!isOpenServerPort)
            {
                MessageBox.Show("请先打开服务端口！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Socket serverSocket = MainForm.getServerSocket();
            if (serverSocket == null){
                return;
            }
            EndPoint endPoint = MainForm.getEndPoint();
            //停用按钮，防止多次点击
            this.tbScanFrequency.Enabled = false;
            this.btnReadFrequency.Enabled = false;
            try
            {
                //如果不为空
                byte[] bmsg = { 0x01, 0x30 };
                if (bmsg != null)
                {
                    //UI显示
                    this.tbScanFrequency.Enabled = true;
                    this.btnReadFrequency.Enabled = true;

                    //开启接收消息线程
                    receiveThread3 = new Thread(ReciveMessage);
                    receiveThread3.Start();

                    //发送数据包
                    serverSocket.SendTo(bmsg, endPoint);
                }
                else
                {
                    MessageBox.Show("发送数据格式错误：" + bmsg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (SocketException es)
            {
                MessageBox.Show("发送数据报时出现异常：" + es.ErrorCode + "！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.tbScanFrequency.Enabled = true;
            this.btnReadFrequency.Enabled = true;
        }

        private void btnResetFrequency_Click(object sender, System.EventArgs e)
        {
            bool isOpenServerPort = MainForm.getOpenServerPort();
            if (!isOpenServerPort)
            {
                MessageBox.Show("请先打开服务端口！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Socket serverSocket = MainForm.getServerSocket();
            if (serverSocket == null){
                return;
            }
            EndPoint endPoint = MainForm.getEndPoint();
            //停用按钮，防止多次点击
            this.tbScanFrequency.Enabled = false;
            this.btnResetFrequency.Enabled = false;
            try
            {
                short frequency = Convert.ToInt16(this.tbScanFrequency.Text);
                byte data = Convert.ToByte(frequency);
                //如果不为空
                byte[] bmsg = { 0x01, 0x2E, data };
                if (bmsg != null)
                {
                    //UI显示
                    this.tbScanFrequency.Enabled = true;
                    this.btnResetFrequency.Enabled = true;

                    //发送数据包
                    serverSocket.SendTo(bmsg, endPoint);
                }
                else
                {
                    MessageBox.Show("发送数据格式错误：" + bmsg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (SocketException es)
            {
                MessageBox.Show("发送数据报时出现异常：" + es.ErrorCode + "！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.tbScanFrequency.Enabled = true;
            this.btnResetFrequency.Enabled = true;
        }

        private void btnReadPeak_Click(object sender, EventArgs e)
        {
            bool isOpenServerPort = MainForm.getOpenServerPort();
            if (!isOpenServerPort)
            {
                MessageBox.Show("请先打开服务端口！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Socket serverSocket = MainForm.getServerSocket();
            if (serverSocket == null){
                return;
            }
            EndPoint endPoint = MainForm.getEndPoint();
            //停用按钮，防止多次点击
            this.btnReadPeak.Enabled = false;
            try
            {
                //如果不为空
                byte[] bmsg = { 0x01, 0x34 };
                if (bmsg != null)
                {

                    //UI显示
                    this.btnReadPeak.Enabled = true;

                    //开启接收消息线程
                    receiveThread3 = new Thread(ReciveMessage);
                    receiveThread3.Start();

                    //发送数据包
                    serverSocket.SendTo(bmsg, endPoint);
                }
                else
                {
                    MessageBox.Show("发送数据格式错误：" + bmsg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (SocketException es)
            {
                MessageBox.Show("发送数据报时出现异常：" + es.ErrorCode + "！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.btnReadPeak.Enabled = true;
        }

        private void btnWritePeak_Click(object sender, EventArgs e)
        {
            bool isOpenServerPort = MainForm.getOpenServerPort();
            if (!isOpenServerPort)
            {
                MessageBox.Show("请先打开服务端口！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Socket serverSocket = MainForm.getServerSocket();
            if (serverSocket == null){
                return;
            }
            EndPoint endPoint = MainForm.getEndPoint();
            //停用按钮，防止多次点击
            this.btnWritePeak.Enabled = false;
            try
            {
                //如果不为空
                byte[] bmsg = { 0x01, 0x32, tbPeakSeekParam1.Text.ToByte(), tbPeakSeekParam2.Text.ToByte(), tbPeakSeekParam3.Text.ToByte(), tbPeakSeekParam4.Text.ToByte(),
                                            tbPeakSeekParam5.Text.ToByte(), tbPeakSeekParam6.Text.ToByte(), tbPeakSeekParam7.Text.ToByte(), tbPeakSeekParam8.Text.ToByte(),
                                            tbPeakSeekParam9.Text.ToByte(), tbPeakSeekParam10.Text.ToByte(), tbPeakSeekParam11.Text.ToByte(), tbPeakSeekParam12.Text.ToByte(),
                                            tbPeakSeekParam13.Text.ToByte(), tbPeakSeekParam14.Text.ToByte(), tbPeakSeekParam15.Text.ToByte(), tbPeakSeekParam16.Text.ToByte(),};
                if (bmsg != null)
                {
                    //UI显示
                    this.btnWritePeak.Enabled = true;

                    //发送数据包
                    serverSocket.SendTo(bmsg, endPoint);
                }
                else
                {
                    MessageBox.Show("发送数据格式错误：" + bmsg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (SocketException es)
            {
                MessageBox.Show("发送数据报时出现异常：" + es.ErrorCode + "！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.btnWritePeak.Enabled = true;
        }

        private void tbFlexWave1_TextChanged(object sender, EventArgs e)
        {
            if (tbFlexWave1.Text.Length > 0)
            {
                S1A1 = Convert.ToDouble(this.tbFlexWave1.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbFlexWave1"].Value = tbFlexWave1.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbTempWave1_TextChanged(object sender, EventArgs e)
        {
            if (tbTempWave1.Text.Length > 0)
            {
                S1A2 = Convert.ToDouble(this.tbTempWave1.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbTempWave1"].Value = tbTempWave1.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbStrainCoefficient1_TextChanged(object sender, EventArgs e)
        {
            if (tbStrainCoefficient1.Text.Length > 0)
            {
                S1K1 = Convert.ToDouble(this.tbStrainCoefficient1.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbStrainCoefficient1"].Value = tbStrainCoefficient1.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbTempCoefficient1_TextChanged(object sender, EventArgs e)
        {
            if (tbTempCoefficient1.Text.Length > 0)
            {
                S1K2 = Convert.ToDouble(this.tbTempCoefficient1.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbTempCoefficient1"].Value = tbTempCoefficient1.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbStrainTempCoefficient1_TextChanged(object sender, EventArgs e)
        {
            if (tbStrainTempCoefficient1.Text.Length > 0)
            {
                S1K3 = Convert.ToDouble(this.tbStrainTempCoefficient1.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbStrainTempCoefficient1"].Value = tbStrainTempCoefficient1.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbFlexWave2_TextChanged(object sender, EventArgs e)
        {
            if (tbFlexWave2.Text.Length > 0)
            {
                S2A1 = Convert.ToDouble(this.tbFlexWave2.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbFlexWave2"].Value = tbFlexWave2.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbTempWave2_TextChanged(object sender, EventArgs e)
        {
            if (tbTempWave2.Text.Length > 0)
            {
                S2A2 = Convert.ToDouble(this.tbTempWave2.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbTempWave2"].Value = tbTempWave2.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbStrainCoefficient2_TextChanged(object sender, EventArgs e)
        {
            if (tbStrainCoefficient2.Text.Length > 0)
            {
                S2K1 = Convert.ToDouble(this.tbStrainCoefficient2.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbStrainCoefficient2"].Value = tbStrainCoefficient2.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbTempCoefficient2_TextChanged(object sender, EventArgs e)
        {
            if (tbTempCoefficient2.Text.Length > 0)
            {
                S2K2 = Convert.ToDouble(this.tbTempCoefficient2.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbTempCoefficient2"].Value = tbTempCoefficient2.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbStrainTempCoefficient2_TextChanged(object sender, EventArgs e)
        {
            if (tbStrainTempCoefficient2.Text.Length > 0)
            {
                S2K3 = Convert.ToDouble(this.tbStrainTempCoefficient2.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbStrainTempCoefficient2"].Value = tbStrainTempCoefficient2.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbElasticModulus1_TextChanged(object sender, EventArgs e)
        {
            if (tbElasticModulus1.Text.Length > 0)
            {
                EM1 = Convert.ToDouble(this.tbElasticModulus1.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbElasticModulus1"].Value = tbElasticModulus1.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbElasticModulus2_TextChanged(object sender, EventArgs e)
        {
            if (tbElasticModulus2.Text.Length > 0)
            {
                EM2 = Convert.ToDouble(this.tbElasticModulus2.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbElasticModulus2"].Value = tbElasticModulus2.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbAxialForce1_TextChanged(object sender, EventArgs e)
        {
            if (tbAxialForce1.Text.Length > 0)
            {
                AF1 = Convert.ToDouble(this.tbAxialForce1.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbAxialForce1"].Value = tbAxialForce1.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbAxialForce2_TextChanged(object sender, EventArgs e)
        {
            if (tbAxialForce2.Text.Length > 0)
            {
                AF2 = Convert.ToDouble(this.tbAxialForce2.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbAxialForce2"].Value = tbAxialForce2.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbAxialForce3_TextChanged(object sender, EventArgs e)
        {
            if (tbAxialForce3.Text.Length > 0)
            {
                PE = Convert.ToDouble(this.tbAxialForce3.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbAxialForce3"].Value = tbAxialForce3.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void btnClearInput_Click(object sender, EventArgs e)
        {
            this.tbScanFrequency.Text = "100";
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            app.Settings["tbScanFrequency"].Value = tbScanFrequency.Text;
            config.Save(ConfigurationSaveMode.Modified);
        }

        private void btnClearInput1_Click(object sender, EventArgs e)
        {
            this.tbWaveOffset.Text = "0";
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            app.Settings["tbWaveOffset"].Value = tbWaveOffset.Text;
            config.Save(ConfigurationSaveMode.Modified);
        }

        private void cbAlarmNotify_CheckedChanged(object sender, EventArgs e)
        {
            isAlarmNotify = this.cbAlarmNotify.Checked;
            this.tbAxialForceExceeds.Enabled = isAlarmNotify;
            this.tbRepeatTimes.Enabled = isAlarmNotify;
            this.cbAlarmEmail.Enabled = isAlarmNotify;
            this.tbAlarmEmail.Enabled = isAlarmNotify;
            this.cbAlarmPhone.Enabled = isAlarmNotify;
            this.tbAlarmPhone.Enabled = isAlarmNotify;

            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            AppSettingsSection app = config.AppSettings;
            app.Settings["cbAlarmNotify"].Value = Convert.ToString(isAlarmNotify);
            config.Save(ConfigurationSaveMode.Modified);
        }

        private void tbScanFrequency_TextChanged(object sender, EventArgs e)
        {
            if (tbScanFrequency.Text.Length > 0)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbScanFrequency"].Value = tbScanFrequency.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbWaveOffset_TextChanged(object sender, EventArgs e)
        {
            if (tbWaveOffset.Text.Length > 0)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbWaveOffset"].Value = tbWaveOffset.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbPeakSeekParam1_TextChanged(object sender, EventArgs e)
        {
            if (tbPeakSeekParam1.Text.Length > 0)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbPeakSeekParam1"].Value = tbPeakSeekParam1.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbPeakSeekParam2_TextChanged(object sender, EventArgs e)
        {
            if (tbPeakSeekParam2.Text.Length > 0)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbPeakSeekParam2"].Value = tbPeakSeekParam2.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbPeakSeekParam3_TextChanged(object sender, EventArgs e)
        {
            if (tbPeakSeekParam3.Text.Length > 0)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbPeakSeekParam3"].Value = tbPeakSeekParam3.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbPeakSeekParam4_TextChanged(object sender, EventArgs e)
        {
            if (tbPeakSeekParam4.Text.Length > 0)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbPeakSeekParam4"].Value = tbPeakSeekParam4.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbPeakSeekParam5_TextChanged(object sender, EventArgs e)
        {
            if (tbPeakSeekParam5.Text.Length > 0)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbPeakSeekParam5"].Value = tbPeakSeekParam5.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbPeakSeekParam6_TextChanged(object sender, EventArgs e)
        {
            if (tbPeakSeekParam6.Text.Length > 0)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbPeakSeekParam6"].Value = tbPeakSeekParam6.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbPeakSeekParam7_TextChanged(object sender, EventArgs e)
        {
            if (tbPeakSeekParam7.Text.Length > 0)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbPeakSeekParam7"].Value = tbPeakSeekParam7.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbPeakSeekParam8_TextChanged(object sender, EventArgs e)
        {
            if (tbPeakSeekParam8.Text.Length > 0)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbPeakSeekParam8"].Value = tbPeakSeekParam8.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbPeakSeekParam9_TextChanged(object sender, EventArgs e)
        {
            if (tbPeakSeekParam9.Text.Length > 0)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbPeakSeekParam9"].Value = tbPeakSeekParam9.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbPeakSeekParam10_TextChanged(object sender, EventArgs e)
        {
            if (tbPeakSeekParam10.Text.Length > 0)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbPeakSeekParam10"].Value = tbPeakSeekParam10.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbPeakSeekParam11_TextChanged(object sender, EventArgs e)
        {
            if (tbPeakSeekParam11.Text.Length > 0)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbPeakSeekParam11"].Value = tbPeakSeekParam11.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbPeakSeekParam12_TextChanged(object sender, EventArgs e)
        {
            if (tbPeakSeekParam12.Text.Length > 0)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbPeakSeekParam12"].Value = tbPeakSeekParam12.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbPeakSeekParam13_TextChanged(object sender, EventArgs e)
        {
            if (tbPeakSeekParam13.Text.Length > 0)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbPeakSeekParam13"].Value = tbPeakSeekParam13.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbPeakSeekParam14_TextChanged(object sender, EventArgs e)
        {
            if (tbPeakSeekParam14.Text.Length > 0)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbPeakSeekParam14"].Value = tbPeakSeekParam14.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbPeakSeekParam15_TextChanged(object sender, EventArgs e)
        {
            if (tbPeakSeekParam15.Text.Length > 0)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbPeakSeekParam15"].Value = tbPeakSeekParam15.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbPeakSeekParam16_TextChanged(object sender, EventArgs e)
        {
            if (tbPeakSeekParam16.Text.Length > 0)
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbPeakSeekParam16"].Value = tbPeakSeekParam16.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbAxialForceExceeds_TextChanged(object sender, EventArgs e)
        {
            if ((isAlarmNotify) && (this.tbAxialForceExceeds.Text.Length > 0))
            {
                axialForceExceeds = Convert.ToDouble(this.tbAxialForceExceeds.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbAxialForceExceeds"].Value = Convert.ToString(axialForceExceeds);
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbRepeatTimes_TextChanged(object sender, EventArgs e)
        {
            if ((isAlarmNotify) && (this.tbRepeatTimes.Text.Length > 0))
            {
                repeatTimes = Convert.ToInt16(this.tbRepeatTimes.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbRepeatTimes"].Value = Convert.ToString(repeatTimes);
                config.Save(ConfigurationSaveMode.Modified);
            }

        }

        private void tbAlarmPhone_TextChanged(object sender, EventArgs e)
        {
            if ((this.cbAlarmPhone.Enabled) && (tbAlarmPhone.Text.Length > 0))
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbAlarmPhone"].Value = tbAlarmPhone.Text;
                config.Save(ConfigurationSaveMode.Modified);
                alarmPhone = this.tbAlarmPhone.Text;
            }
        }

        private void cbAlarmEmail_CheckedChanged(object sender, EventArgs e)
        {
            if (isAlarmNotify)
            {
                isAlarmEmail = this.cbAlarmEmail.Checked;
                this.tbAlarmEmail.Enabled = isAlarmEmail;
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["cbAlarmEmail"].Value = Convert.ToString(isAlarmEmail);
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbAlarmEmail_TextChanged(object sender, EventArgs e)
        {
            if ((isAlarmNotify) && (isAlarmEmail) && (this.tbAlarmEmail.Text.Length > 0))
            {
                alarmEmail = this.tbAlarmEmail.Text;
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tbAlarmEmail"].Value = alarmEmail;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void cbAlarmPhone_CheckedChanged(object sender, EventArgs e)
        {
            if (isAlarmNotify)
            {
                isAlarmPhone = this.cbAlarmPhone.Checked;
                this.tbAlarmPhone.Enabled = isAlarmPhone;
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["cbAlarmPhone"].Value = Convert.ToString(isAlarmPhone);
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbTempStartWave_TextChanged(object sender, EventArgs e)
        {
            if (tbTempStartWave.Text.Length > 0)
            {
                tempStartWave = Convert.ToDouble(tbTempStartWave.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tempStartWave"].Value = tbTempStartWave.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbTempStartValue_TextChanged(object sender, EventArgs e)
        {
            if (tbTempStartValue.Text.Length > 0)
            {
                tempStartValue = Convert.ToDouble(tbTempStartValue.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["tempStartValue"].Value = tbTempStartValue.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbStartWave10_TextChanged(object sender, EventArgs e)
        {
            if (tbStartWave10.Text.Length > 0)
            {
                moveStartWave10 = Convert.ToDouble(tbStartWave10.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["moveStartWave10"].Value = tbStartWave10.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbStartWave20_TextChanged(object sender, EventArgs e)
        {
            if (tbStartWave20.Text.Length > 0)
            {
                moveStartWave20 = Convert.ToDouble(tbStartWave20.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["moveStartWave20"].Value = tbStartWave20.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbA_TextChanged(object sender, EventArgs e)
        {
            if (tbA.Text.Length > 0)
            {
                A = Convert.ToDouble(tbA.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["A"].Value = tbA.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbB_TextChanged(object sender, EventArgs e)
        {
            if (tbB.Text.Length > 0)
            {
                B = Convert.ToDouble(tbB.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["B"].Value = tbB.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

        private void tbC_TextChanged(object sender, EventArgs e)
        {
            if (tbC.Text.Length > 0)
            {
                C = Convert.ToDouble(tbC.Text);
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection app = config.AppSettings;
                app.Settings["C"].Value = tbC.Text;
                config.Save(ConfigurationSaveMode.Modified);
            }
        }

    }
}